<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/23
 * Time: 15:23
 *
 * @copyright: ©2024 永州微聚 商网络科技有限公司
 * @link: https://www.weijuYunke.com
 */

namespace app\admin\controller;

use app\Request;

class Level
{
    public function levelList(Request $request)
    {
        $param = $request->param();
        $limit = 10;
        $start = 0;
        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $levelModel = new \app\merchant\model\Level();
        $list = $levelModel->limit($start, $limit)->select()->toArray();
        $count = $levelModel->count();
        return adminSuccess('会员列表', ['list' => $list, 'count' => $count]);
    }

    public function addLevel(Request $request)
    {
        $param = $request->param();
        $data = [
            'name' => $param['name'],
            //'desc' => $param['desc'],
            'consumption_amount' => $param['consumption_amount'],
            'preferential' => $param['preferential'],
            'shopping_preferential' => $param['shopping_preferential'],
            'package_preferential' => $param['package_preferential'],
            'create_time' => time(),
        ];
        $levelModel = new \app\merchant\model\Level();
        $levelModel->insert($data);
        return adminSuccess('添加成功');
    }

    public function editLevel(Request $request)
    {
        $param = $request->param();
        $levelModel = new \app\merchant\model\Level();

            $data = [
                'name' => $param['name'],
                //'desc' => $value->desc,
                'consumption_amount' => $param['consumption_amount'],
                'preferential' => $param['preferential'],
                'shopping_preferential' => $param['shopping_preferential'],
                'package_preferential' => $param['package_preferential'],
                'create_time' => time()
            ];
            if (isset($param['status'])) {
                $data['status'] = $param['status'];
            }
            $levelModel->where(['id' => $param['id']])->update($data);


        return adminSuccess('修改成功');
    }

}